package web;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import model.Category;
import model.Item;

import server.CategoryItemsRepository;
import server.CategoryRepository;

@Path("/rest/category")
public class CategoryController
{
	private final CategoryRepository categoryRepository = new CategoryRepository();
	private final CategoryItemsRepository categoryItemsRepository = new CategoryItemsRepository();
	
	@GET
	@Produces({MediaType.APPLICATION_JSON})
	@Path("/get/{categoryID}")
	public Item fetchCategoryItem(@PathParam("categoryID") Long categoryID)
	{
		Category category = categoryRepository.getById(categoryID);
		Item item = null;
		
		if (category != null)
		{
			//TODO randomise item
			item = categoryItemsRepository.getById(categoryID).getItemList().get(0);
		}
		
		return item;
	}
}
